﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShareCode.Util.Helper
{
    public class DateTimeHelper
    {
        public static int GetTimeStamp()
        {
            return ConvertDateTime2Int(DateTime.Now);
        }

        public static int ConvertDateTime2Int(DateTime time)
        {
            int intResult = 0;
            DateTime startTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 8, 0, 0), TimeZoneInfo.Local);
            intResult = int.Parse((time - startTime).TotalSeconds.ToString().Substring(0, 10));
            return intResult > 0 ? intResult : 0;
        }

        public static DateTime ConvertInt2Datetime(int utc)
        {
            DateTime startTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 8, 0, 0), TimeZoneInfo.Local);
            startTime = startTime.AddSeconds(utc);
            return startTime;
        }

        public static DateTime GetMonthFirstDay()
        {
            int year = DateTime.Now.Year;
            int month = DateTime.Now.Month;
            DateTime firstDayOfThisMonth = new DateTime(year, month, 1);
            return firstDayOfThisMonth;
        }
    }

}
